package com.example.mydefinedview1.ui

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View

/**
 *
 * @Author： LJH
 * @Time： 2022/6/29
 * @description：
 */
class PieChartView(context: Context, attr:AttributeSet?):View(context,attr) {
    private val paint = Paint()
    private val path = Path()

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        paint.isAntiAlias = true
        paint.color = Color.RED
        canvas?.drawArc(180F,88F,495F,400F,-179F,125F,true,paint)
        //蓝色
        paint.color = Color.parseColor("#2196F3")
        canvas?.drawArc(188F,100F,500F,410F,179F,-106F,true,paint)
        //黄色
        paint.color = Color.parseColor("#FFC107")
        canvas?.drawArc(188F,100F,500F,410F,-3F,-51F,true,paint)
        //绿色
        paint.color = Color.parseColor("#009688")
        canvas?.drawArc(188F,100F,500F,410F,12F,59F,true,paint)
        //灰色
        paint.color = Color.parseColor("#9E9E9E")
        canvas?.drawArc(188F,100F,500F,410F,2F,12F,true,paint)
        //红色
        paint.color = Color.parseColor("#9C27B0")
        canvas?.drawArc(188F,100F,500F,410F,-2F,11F,true,paint)

        paint.color = Color.WHITE
        canvas?.drawText("Kotlin",82F,100F,paint)
        paint.style = Paint.Style.STROKE
        path.moveTo(120F,100F)
        path.run {
            lineTo(220F,100F)
            lineTo(238F,133F)
        }
        canvas?.drawPath(path,paint)
    }
}